package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.CoreKnowledgeBase;
import com.corechina.apex_osswords.domain.entity.CoreKnowledgeBaseType;
import com.corechina.apex_osswords.service.ICoreKnowledgeBaseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 知识库分类表 前端控制器
 * </p>
 *
 * @author fyh
 * @since 2023-02-03
 */

@Api(tags = "知识库分类")
@RestController
@RequestMapping("/core/knowledgeBaseType")
public class CoreKnowledgeBaseTypeController {

    @Autowired
    private ICoreKnowledgeBaseTypeService iCoreKnowledgeBaseTypeService;

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return Response.ok(iCoreKnowledgeBaseTypeService.getById(id));
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(String name, Integer pageIndex, Integer pageSize) {
        return iCoreKnowledgeBaseTypeService.getList(name, pageIndex, pageSize);
    }

    @SysLog("新增知识库分类")
    @ApiOperation("新增")
    @PostMapping("/add")
    public Response add(@RequestBody CoreKnowledgeBaseType coreKnowledgeBaseType){
        coreKnowledgeBaseType.setEnterpriseId(ShiroUtils.getEnterpriseId());
        if(iCoreKnowledgeBaseTypeService.save(coreKnowledgeBaseType)){
            return Response.ok();
        }
        return Response.error();
    }

    @SysLog("删除知识库分类")
    @ApiOperation("删除")
    @DeleteMapping("/del")
    public Response del(Integer id){
        if(iCoreKnowledgeBaseTypeService.removeById(id)){
            return Response.ok();
        }
        return  Response.error();
    }

    @SysLog("编辑知识库分类")
    @ApiOperation("编辑")
    @PutMapping("/update")
    public Response update(@RequestBody CoreKnowledgeBaseType coreKnowledgeBaseType){
        coreKnowledgeBaseType.setEnterpriseId(null);
        if(iCoreKnowledgeBaseTypeService.updateById(coreKnowledgeBaseType)){
            return  Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("微信列表")
    @GetMapping("/getListForWeiXin")
    public Response getListForWeiXin(Integer pageIndex, Integer pageSize) {
        return iCoreKnowledgeBaseTypeService.getListForWeiXin(pageIndex, pageSize);
    }
}

